<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ajax.jsp</title>
</head>
<body>
	<div id="show"></div>
		<hr style="width:100%; clear:left;"/>
		<input name="name" value="b&c=d"/><button>发送get</button><button>发送post</button>
		<script type="text/javascript">
			var show = document.getElementById("show");
			var btns = document.body.querySelectorAll("button");
			var a = document.querySelector("input");

			btns[0].addEventListener("click",function(){
				let xhr = new XMLHttpRequest();
				xhr.onreadystatechange=function(){
					console.info(xhr.readyState+":"+xhr.status);
					if(xhr.readyState==4&&xhr.status==200){
						console.info(xhr.responseText);
						show.innerHTML += xhr.responseText;
					}
				}
				console.info("inc.jsp?name="+encodeURIComponent(a.value));
				xhr.open("get","inc.jsp?name="+encodeURIComponent(a.value),true);
				xhr.send();
			});
			
			btns[1].addEventListener("click",function(){
				let xhr = new XMLHttpRequest();
				xhr.onreadystatechange=function(){
					console.info(xhr.readyState+":"+xhr.status);
					if(xhr.readyState==4&&xhr.status==200){
						console.info(xhr.responseText);
						show.innerHTML += xhr.responseText;
					}
				}
				xhr.open("post","inc.jsp",true);
				xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
				xhr.send("name="+encodeURIComponent(a.value));
			});
			
</body>
</html>